package com.forever.music;

import java.util.ArrayList;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<Map<String, Object>> mdata;
	private MyApplication mApp;
	

	public MyAdapter(MyApplication app, Context context,
			ArrayList<Map<String, Object>> data) {
		mApp = app;
		mContext = context;
		mdata = data;
		
	}

	public int getCount() {
		Log.i("musicDemo", "Lyric ^^^^^^getCount**********" + mdata.size());
		return mdata.size();
	}
	
	

	public Object getItem(int position) {

		return mdata.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
	

	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;

		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);

			holder = new ViewHolder();
			holder.textView1 = (TextView) convertView.findViewById(R.id.list_item_textView_1);
			holder.textView2 = (TextView) convertView.findViewById(R.id.list_item_textView_2);
			holder.textView3 = (TextView) convertView.findViewById(R.id.list_item_textView_3);

			convertView.setTag(holder);

			Log.i("getView", "getView()****view=null******position" + position);
		} else {
			holder = (ViewHolder) convertView.getTag();
			Log.i("getView", "getView()****view!=null******position" + position);
		}

		holder.textView1.setText(mdata.get(position).get("number").toString());
		holder.textView2.setText(mdata.get(position).get("name").toString());
		holder.textView3.setText(mdata.get(position).get("musicTime").toString());
		
		if (mApp.current == position-1) {
			for(int i=0; i< mApp.getListView().getChildCount(); i++) {
				mApp.getListView().getChildAt(i).setPressed(false);
				Log.i("MusicDemoBug22","bug             " + mApp.getListView().getChildCount());
			}
			mApp.getListView().getChildAt(mApp.current).setPressed(true);
			
		}
		
		return convertView;
	}

	public static class ViewHolder {
		public TextView textView1;
		public TextView textView2;
		public TextView textView3;
	}

}
